.milkdown {
  .milkdown-code-block {
    display: block;
    position: relative;
    padding: 8px 20px 20px;
    background: var(--crepe-color-surface);
    margin: 4px 0;

    .language-picker {
      padding-top: 10px;
      width: max-content;
      position: absolute;
      z-index: 999;
    }

    .hidden {
      display: none !important;
    }

    &.selected {
      outline: 1px solid var(--crepe-color-primary);
    }

    .cm-editor {
      outline: none !important;
      background: var(--crepe-color-surface);
      font-size: 18px;
    }

    .cm-activeLine {

    }

    .cm-gutters {
      border-right: none;
      background: var(--crepe-color-surface);

      /*不允许选择*/
      user-select: none;

      .cm-activeLineGutter {
        /*background: none;*/
        background: #6699ff0b;
      }
    }

    .cm-panel {
      font-family: var(--crepe-font-default), serif;
      background: var(--crepe-color-surface);
      color: var(--crepe-color-on-surface);

      input {
        caret-color: var(--crepe-color-outline);
        border-radius: 4px;
        background: var(--crepe-color-surface-low);
      }

      & > button {
        text-transform: capitalize;
        background: var(--crepe-color-surface-low);
        color: var(--crepe-color-on-surface-variant);
        border: 1px solid var(--crepe-color-outline);
        font-weight: 600;
        cursor: pointer;
        border-radius: 4px;

        &:hover {
          background: var(--crepe-color-hover);
        }
      }

      & > label {
        display: inline-flex;
        align-items: center;
        text-transform: capitalize;

        input[type='checkbox'] {
          border-radius: 4px;
          cursor: pointer;
          appearance: none;
          -webkit-appearance: none;
          background: var(--crepe-color-surface-low);
          width: 1.15em;
          height: 1.15em;
          border: 1px solid var(--crepe-color-outline);
          display: grid;
          place-content: center;

          &::before {
            content: '';
            transform-origin: bottom left;
            width: 0.65em;
            height: 0.65em;
            transform: scale(0);
            transition: 120ms transform ease-in-out;
            box-shadow: inset 1em 1em var(--crepe-color-outline);
            clip-path: polygon(
              14% 44%,
              0 65%,
              50% 100%,
              100% 16%,
              80% 0%,
              43% 62%
            );
          }

          &:checked::before {
            transform: scale(1);
          }
        }
      }
    }

    .tools {
      display: flex;
      justify-content: space-between;
      align-items: center;

      input {
        caret-color: var(--crepe-color-outline);
      }

      .preview-toggle-button {
        background: var(--crepe-color-secondary);
        color: var(--crepe-color-on-surface-variant);
        padding: 4px 10px;
        opacity: 0;
        cursor: pointer;
        border-radius: 100px;
        font-size: 16px;
        line-height: 16px;
        font-weight: 600;
        font-family: var(--crepe-font-default), serif;
        transition: opacity 0.2s ease-in-out;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;

        svg {
          width: 14px;
          height: 14px;
          fill: var(--crepe-color-on-surface-variant);
        }
      }

      .language-button {
        display: flex;
        align-items: center;
        font-family: var(--crepe-font-default), serif;
        gap: 6px;
        padding: 2px 4px 2px 8px;
        background: var(--crepe-color-surface-low);
        color: var(--crepe-color-on-surface-variant);
        border-radius: 4px;
        font-size: 12px;
        font-weight: 600;
        line-height: 16px;
        margin-bottom: 8px;
        /*opacity: 0;*/
        cursor: pointer;
        transition: opacity 0.2s ease-in-out;

        &:hover {
          background: var(--crepe-color-hover);
        }

        .expand-icon {
          transition: transform 0.2s ease-in-out;
          width: 18px;
          height: 18px;
          display: flex;
          justify-content: center;
          align-items: center;
        }

        .expand-icon svg {
          width: 14px;
          height: 14px;
          color: var(--crepe-color-outline);
        }

        &[data-expanded='true'] .expand-icon {
          transform: rotate(180deg);
        }

        .expand-icon svg:focus,
        .expand-icon:focus-visible {
          outline: none;
        }
      }
    }

    &:hover .language-button {
      opacity: 1;
    }

    &:hover .preview-toggle-button {
      opacity: 1;
    }

    .list-wrapper {
      background: var(--crepe-color-surface-low);
      border-radius: 12px;
      box-shadow: var(--crepe-shadow-1);
      width: 240px;
      padding-top: 12px;
    }

    .language-list {
      max-height: 300px;
      overflow-y: auto;
      overscroll-behavior: contain;
      margin: 0;
      padding: 0;
    }

    .language-list-item {
      cursor: pointer;
      margin: 0;
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 4px 22px;
      font-size: 14px;
      font-weight: 600;
      line-height: 20px;

      &:hover {
        background: var(--crepe-color-hover);
      }

      &:focus-visible {
        outline: none;
        background: var(--crepe-color-hover);
      }

      .leading,
      .leading svg {
        width: 24px;
        height: 24px;
      }

      &.no-result {
        cursor: default;
        opacity: 0.6;

        &:hover {
          background: transparent;
        }
      }
    }

    .search-box {
      display: flex;
      align-items: center;
      margin: 0 12px 8px;
      background: transparent;
      border-radius: 4px;
      outline: 1px solid var(--crepe-color-primary);
      gap: 8px;
      padding: 6px 10px;

      &:has(input:focus) {
        outline: 2px solid var(--crepe-color-primary);
      }

      .search-input {
        width: 100%;
        color: var(--crepe-color-on-surface);
      }

      .search-icon {
        display: none;
      }

      .clear-icon {
        cursor: pointer;
        width: 20px;
        height: 20px;

        svg {
          width: 20px;
          height: 20px;
          color: var(--crepe-color-primary);
          fill: var(--crepe-color-primary);
        }

        &:hover {
          background: var(--crepe-color-hover);
        }
      }

      input {
        font-family: var(--crepe-font-default), serif;
        font-size: 14px;
        line-height: 20px;
        background: transparent;
      }

      input:focus {
        outline: none;
      }
    }

    .preview-panel {
      .preview-divider {
        height: 1px;
        opacity: 0.2;
        background: var(--crepe-color-outline);
        margin: 6px 0;
      }

      .preview-label {
        margin: 6px 0;
        font-size: 12px;
        color: color-mix(
          in srgb,
          var(--crepe-color-on-surface),
          transparent 40%
        );
        font-weight: 600;
        text-transform: uppercase;
        font-family: var(--crepe-font-default), serif;
      }

      .preview {
        text-align: center;
        overflow-x: auto;
      }
    }
  }
}
